/*
 * @ProjectName: 编程学习
 * @Copyright:   2019 HangZhou Yi Dev, Ltd. All Right Reserved.
 * @address:     https://yiyuery.github.io/
 * @date:        2019/5/20 20:57
 * @email:       xiazhaoyang@live.com
 * @description: 本内容仅限于编程技术学习使用，转发请注明出处.
 */
package com.example.component.gallery.common.util;

import com.example.common.util.CapDateTimeUtil;
import com.example.common.util.RunnerMonitor;
import com.example.component.gallery.common.enums.ImageStorageEnum;

import java.io.File;
import java.nio.file.Paths;

/**
 * <p>
 *
 * </p>
 *
 * @author Yi
 * @version v1.0.0
 * @date 2019-07-24 23:59
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2019-07-24
 * @modify reason: {方法名}:{原因}
 * ...
 */
public class ImageHelper {

    public static File IMAGE_LOCAL_CACHE_DIR = getImageLocalCacheDir();

    /**
     * 根据运行环境加载图片持久化保存路径
     * @return
     */
    public static String getStoragePath() {
        String path = "";
        switch (RunnerMonitor.getOSType()) {
            case OS_NAME_MAC:
                path = ImageStorageEnum.OS_MAC_IMAGE_STORAGE_PATH.getPath();
                break;
            case OS_NAME_LINUX:
                path = ImageStorageEnum.OS_LINUX_IMAGE_STORAGE_PATH.getPath();
                break;
            default:
                break;
        }
        return path;
    }

    /**
     * 加载本地图片保存路径
     * @return
     */
    public static File getImageLocalCacheDir(){
        return Paths.get(getStoragePath(), CapDateTimeUtil.getInstance().dateFormat(CapDateTimeUtil.currentTimeMillis(), CapDateTimeUtil.DateFormatConstant.YYMM)).toFile();
    }
}
